package test1;

public class MyThread extends Thread{
    static Integer num = 0;

    //锁对象,一定要是唯一的
    static Object obj = new Object();

    @Override
    public void run() {
        while (true){
            //同步代码块，通常会使用字节码文件对象
            synchronized (MyThread.class){
                if (num < 100){
                    System.out.println(Thread.currentThread().getName() + String.format("卖第"+num+"张票"));
                    num ++;
                }else{
                    break;
                }
            }


        }

    }

//    public MyThread(int ticketNum) {
//        num = ticketNum;
//    }
}
